package com.project.andeper.paperproject;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

/**
 * Created by 15888 on 2016/9/24.
 */
public class TimeDataAdapter extends BaseAdapter {

    private List<Map<String, Object>> data;
    private LayoutInflater layoutInflater;
    private Context context;

    public TimeDataAdapter(Context context,List<Map<String, Object>> data){
        this.context=context;
        this.data=data;
        this.layoutInflater=LayoutInflater.from(context);
    }
    public final class Zujian{
        public TextView number;
        public TextView model;
        public TextView info;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Zujian zujian = null;
        if(view==null){
            zujian=new Zujian();
            //获得组件，实例化组件
            view=layoutInflater.inflate(R.layout.hourdatalist_item, null);
            zujian.model=(TextView)view.findViewById(R.id.hour_model);
            zujian.number=(TextView)view.findViewById(R.id.hour_number);
            zujian.info=(TextView)view.findViewById(R.id.hour_info);
            view.setTag(zujian);
        }else{
            zujian=(Zujian)view.getTag();
        }
        //绑定数据
        zujian.model.setText((String)data.get(i).get("model"));
        zujian.number.setText((String)data.get(i).get("number"));
        zujian.info.setText("耗电量:  " + data.get(i).get("info").toString());
        return view;
    }
}
